package a.storeGenerator.ruToken;

import java.io.IOException;

import ru.signalcom.io.TokenFile;
import ru.signalcom.io.TokenFileInputStream;
import ru.signalcom.io.TokenFileOutputStream;

public class TokenStoreUtil {
/*	String root;
	public TokenUtil(String root) {
		this.root = root;
	}*/

	public void createFolder(String foldername){
		TokenFile file = new TokenFile(foldername);
		if (file.exists()) return;
		if (file.isDirectory()) return;
		file.mkdir();
//		file.setReadable(true);
//		file.setWritable(true);
	}
	
	public void fwrite(String fname, byte[] data) throws IOException {
		TokenFileOutputStream stream = new TokenFileOutputStream(new TokenFile(fname));
		stream.write(data);
		stream.close();
	}

	public byte[] fread(String fname) throws IOException {
		byte[] data = null;

		TokenFile file = new TokenFile(fname);
		TokenFileInputStream stream = new TokenFileInputStream(file);
		data = new byte[(int) file.length()];
		stream.read(data);
		stream.close();
		return data;
	}
}
